import os

this_path = os.path.abspath(os.path.dirname(__file__))


def create_project_structure(filename: str):
    with open(filename, 'r') as f:
        lines = f.readlines()
        path_list = []
        for line in lines:
            indent_level = line.count('    ')
            line = line.strip()
            path_list = path_list[:indent_level]
            if not line.startswith('/'):
                line = '/' + line
            path_list.append(line)
            current_path = this_path + ''.join(path_list)
            if '.' in line or 'file' in line.lower():  # It's a file
                with open(current_path, 'w') as file:
                    if line.endswith('.go'):
                        file.write('// This empty file was generated automatically\n')
            else:  # It's a directory
                os.makedirs(current_path, exist_ok=True)


if __name__ == '__main__':
    argv_len = len(sys.argv)
    if argv_len < 2:
        print('err usage', __file__, '<structFilePath>')
    else:
        create_structure_file(sys.argv[1])
